from browser . logic import browser_logic

class mediator_fake :
    def __init__ ( self ) :
        self . _knowledge_bases_fetched = None
        self . _knowledge_base_receiving_callback = None
        self . _all_knowledge_bases = [ ]
        self . _selection_history = [ ]
        self . _entry_text = None
        self . _entry_focused = False
        self . _call_history = [ ]
        self . _bold_table_row_history = [ ]
    def add_title_label_to_browser ( self , title_text ) :
        pass
    def add_table_to_browser ( self ) :
        pass
    def add_return_button_to_browser ( self ) :
        pass
    def add_action_button_to_browser ( self , action_text ) :
        pass
    def add_title_row_to_browser ( self , number , name , creation_time , modification_time , size ) :
        pass
    def add_existing_row_to_browser ( self , number , name , creation_time , modification_time , size ) :
        pass
    def add_empty_row_to_browser ( self ) :
        pass
    def add_action_row_to_browser ( self ) :
        pass
    def set_entry_text_in_browser ( self , text ) :
        self . _call_history += [ mediator_fake . set_entry_text_in_browser ]
        self . _entry_text = text
    def focus_entry_in_browser ( self ) :
        self . _call_history += [ mediator_fake . focus_entry_in_browser ]
        self . _entry_focused = True
    def unfocus_entry_in_browser ( self ) :
        self . _call_history += [ mediator_fake . unfocus_entry_in_browser ]
        self . _entry_focused = False
    def select_table_row ( self , row ) :
        self . _call_history += [ mediator_fake . select_table_row ]
        self . _selection_history += [ [ mediator_fake . select_table_row , row ] ]
    def unselect_table_row ( self , row ) :
        self . _call_history += [ mediator_fake . unselect_table_row ]
        self . _selection_history += [ [ mediator_fake . unselect_table_row , row ] ]
    def localization_browser_number ( self ) :
        pass
    def localization_browser_existing_name ( self ) :
        pass
    def localization_browser_creation_time ( self ) :
        pass
    def localization_browser_modification_time ( self ) :
        pass
    def localization_browser_size ( self ) :
        pass
    def fetch_all_knowledge_bases ( self ) :
        self . _knowledge_bases_fetched = True
        for kb in self . _all_knowledge_bases :
            self . _knowledge_base_receiving_callback ( * kb )
    def bold_table_row ( self , row ) :
        self . _bold_table_row_history += [ [ mediator_fake . bold_table_row , row ] ]
    def unbold_table_row ( self , row ) :
        self . _bold_table_row_history += [ [ mediator_fake . unbold_table_row , row ] ]
    
class browser_logic_on_table_row_click_tests :
    'browser_logic_on_table_row_click'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _browser_logic = browser_logic ( self . _mediator )
    def test_on_table_row_click_select_item ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'name1' , None , 'time1' , None ]
            , [ 'name2' , None , 'time2' , None ]
            , [ 'name3' , None , 'time3' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _selection_history = [ ]
        self . _browser_logic . on_table_row_click ( 2 )
        self . _test . assume_equal ( self . _mediator . _selection_history ,
            [ [ mediator_fake . unselect_table_row , 3 ]
            , [ mediator_fake . select_table_row , 2 ]
            ] )
    def test_on_table_row_click_invalid_row ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'name1' , None , 'time1' , None ]
            , [ 'name2' , None , 'time2' , None ]
            , [ 'name3' , None , 'time3' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _selection_history = [ ]
        self . _browser_logic . on_table_row_click ( 100 )
        self . _test . assume_empty ( self . _mediator . _selection_history )
    def test_on_table_row_click_select_subsequent_items ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'name1' , None , 'time1' , None ]
            , [ 'name2' , None , 'time2' , None ]
            , [ 'name3' , None , 'time3' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _browser_logic . on_table_row_click ( 2 )
        self . _mediator . _selection_history = [ ]
        self . _browser_logic . on_table_row_click ( 1 )
        self . _test . assume_equal ( self . _mediator . _selection_history ,
            [ [ mediator_fake . unselect_table_row , 2 ]
            , [ mediator_fake . select_table_row , 1 ]
            ] )
    def test_on_table_row_click_focus_entry ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'name1' , None , 'time1' , None ]
            , [ 'name2' , None , 'time2' , None ]
            , [ 'name3' , None , 'time3' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _entry_focused = None
        self . _browser_logic . on_table_row_click ( 2 )
        self . _test . assume_true ( self . _mediator . _entry_focused )
    def test_on_table_row_click_copy_selected_item_name_to_text_entry ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'name1' , None , 'time1' , None ]
            , [ 'name2' , None , 'time2' , None ]
            , [ 'name3' , None , 'time3' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _browser_logic . on_table_row_click ( 2 )
        self . _test . assume_equal ( self . _mediator . _entry_text , 'name2' )
    def test_on_table_row_click_do_nothing_before_show ( self ) :
        self . _mediator . _call_history = [ ]
        self . _browser_logic . on_table_row_click ( 1 )
        self . _test . assume_empty ( self . _mediator . _call_history )
    def test_on_table_row_click_do_nothing_after_hide ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'name1' , None , 'time1' , None ]
            , [ 'name2' , None , 'time2' , None ]
            , [ 'name3' , None , 'time3' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _browser_logic . hide_browser ( )
        self . _mediator . _call_history = [ ]
        self . _browser_logic . on_table_row_click ( 2 )
        self . _test . assume_empty ( self . _mediator . _call_history )
    def test_on_table_row_click_make_selected_row_font_bold ( self ) :
        self . _mediator . _knowledge_base_receiving_callback = self . _browser_logic . receive_knowledge_base
        self . _mediator . _all_knowledge_bases = \
            [ [ 'name1' , None , 'time3' , None ]
            , [ 'name2' , None , 'time2' , None ]
            , [ 'name3' , None , 'time1' , None ]
            ]
        self . _browser_logic . show_browser ( )
        self . _mediator . _bold_table_row_history = [ ]
        self . _browser_logic . on_table_row_click ( 2 )
        self . _test . assume_equal ( self . _mediator . _bold_table_row_history ,
            [ [ mediator_fake . unbold_table_row , 1 ]
            , [ mediator_fake . bold_table_row , 2 ]
            ] )
